#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Project ：Employment_class 
@File    ：04_TCP模拟QQ聊天.py
@IDE     ：PyCharm 
@Author  ：XiaoDengYa
@Date    ：2021/6/25/025 20:30 
"""

from socket import *
from threading import Thread

def main(newSocket):

    while True:
        recvData = newSocket.recv(1024)

        if len(recvData) > 0:
            print("recvData:",recvData)
        else:
            break

        data = input("请输入要发送的数据:")
        newSocket.send(data.encode("gb2312"))

    newSocket.close()

if __name__ == '__main__':

    clinetSocket = socket(AF_INET,SOCK_STREAM)

    clinetSocket.bind(("",8899))

    clinetSocket.listen(5)

    while True:
        newSocket, clinetAddr = clinetSocket.accept()
        thread = Thread(target=main,args=(newSocket,))
        thread.start()
        thread.join()

